package com.jh.user.pojo.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

import static com.google.common.base.Strings.isNullOrEmpty;

public enum ChannelTag {
    CHANPAYNEWCARD_04(1,"CHANPAYNEWCARD_04", "代还商旅04"),
    CHANPAYNEWCARD_0101(2,"CHANPAYNEWCARD_0101", "畅捷新无卡101"),
    CHANPAYNEWCARD_0102(3,"CHANPAYNEWCARD_0102", "畅捷新无卡102"),
    CHANPAYNEWCARD2_04(4,"CHANPAYNEWCARD2_04", "快捷商旅05"),
    CHANPAYNEWCARD_1500(5,"CHANPAYNEWCARD_1500", "落地商户"),
    ;

    private final int code;
    private final String value;
    private final String desc;

    ChannelTag(int code, String value, String desc) {
        this.code = code;
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public int getCode() {
        return code;
    }

    public static ChannelTag of(int val) {
        return of(val, null);
    }

    public static ChannelTag of(int val, ChannelTag defaultStatus) {
        if (val == 0) {
            return defaultStatus;
        }

        for (ChannelTag os : values()) {
            if (val == os.getCode()) {
                return os;
            }
        }
        return defaultStatus;
    }

    public static ChannelTag of(String val) {
        return of(val, null);
    }

    public static ChannelTag of(String val, ChannelTag defaultStatus) {
        if (isNullOrEmpty(val)) {
            return defaultStatus;
        }
        val = val.toUpperCase();
        for (ChannelTag os : values()) {
            if (Objects.equals(os.getValue(), val)) {
                return os;
            }
        }
        return defaultStatus;
    }



}
